package hu.vpszd.entities.customer

import hu.vpszd.entities.BaseEntity

import javax.persistence.*
import javax.validation.constraints.*

@Entity
@Table(name = "Customer")
class Customer extends BaseEntity{
	@NotNull
	String firstName

	@NotNull
	String lastName

	//	1 - male, 0 - female
	@NotNull
	Integer gender

	@NotNull
	Date birthday

	//	Birthplace
	@NotNull
	String birthCountry
	@NotNull
	String birthplace
	@NotNull
	String birthFirstName
	@NotNull
	String birthLastName

	@NotNull
	String citizenship
	@NotNull
	String education
	@NotNull
	String maritalStatus
	@NotNull
	@Embedded
	Address address = new Address()
	@NotNull
	String residency
	@NotNull
	@Pattern(regexp = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})\$")
	String emailAddress
	@NotNull
	String mobilePhone
	@NotNull
	String wiredPhone
	String otherPhone

	@NotNull
	@Embedded
	IDCard idCard = new IDCard()

	@NotNull
	@Embedded
	AddressCard	addressCard = new AddressCard()

	@NotNull
	@Embedded
	TaxCard taxCard	= new TaxCard()

	@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
	List<CheckingAccount> checkingAccounts = []
	
	public List<CheckingAccount> getCheckingAccounts() {
		if (!checkingAccounts) {
			checkingAccounts =  []
		}
		return checkingAccounts
	}
}